package com.zues.thread.method;

import lombok.extern.slf4j.Slf4j;

/**
 * 演示买票
 *
 * @author zues
 * @date 12/7/2024 10:59 下午
 */
@Slf4j(topic = "c.TicketThread")
public class TicketThread implements Runnable {

    int ticket = 100;


    @Override
    public void run() {
        while (true) {
            synchronized (TicketThread.class) {
                if (ticket > 0) {
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    log.info("{} 正在卖票，票号为：{}", Thread.currentThread().getName(), ticket);
                    ticket--;
                } else {
                    break;
                }
            }
        }
    }
}
